package com.fyzk.activity.prize.item;

import android.graphics.Color;
import android.text.Html;
import android.text.Spanned;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

import com.fyzk.activity.app.App;
import com.fyzk.data.AppLotteryInfos;
import com.tyjc.lottery.R;
import com.fyzk.utils.LotteryIDUtils;
import com.fyzk.utils.ScreenUtils;

public class ZCPrizeItem extends PrizeItemBase{

	@Override
	public Spanned formatPrizeNumSpanned(String str) {
		return Html.fromHtml("A vs B");
	}
	
	@Override
	public Spanned formatPrizeNumSpanned() {
		String prizeNum = this.getPrizeNum();
		String[] prizeNums = prizeNum.split(",");
		int arr_length = prizeNums.length;
		StringBuffer stb = new StringBuffer();
		for (int i = 0; i < arr_length; i++) {
			try {
				String num = prizeNums[i];
				stb.append("<font color=\"");
				stb.append(PrizeItemBase.COLOR_RED);
				stb.append("\">");
				stb.append(num + "&nbsp");
				stb.append("</font>");
			} catch (Exception e) {
				stb.append("<font color=\"");
				stb.append("数据错误");
				stb.append("\">");
			}
		}
		return Html.fromHtml(stb.toString());
	}

	@Override
	public void initNumView(View view) {
		LinearLayout layout = (LinearLayout) view;
		layout.removeAllViews();
		try{
			String prizeNum = this.getPrizeNum();
			String[] nums = prizeNum.split(",");
			TextView txt = new TextView(App.getContext());
			float density = ScreenUtils.getInstance().getDensity();
			LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
					(int) (30 * density));

			txt.setLayoutParams(layoutParams);
			txt.setGravity(Gravity.CENTER);
			txt.setTextColor(Color.RED);
			txt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
			StringBuffer sb = new StringBuffer();
			for(int i = 0 ; i < nums.length ; i++){
				sb.append(nums[i]);
				sb.append(" ");
			}
			txt.setText(sb.toString());
			layout.addView(txt);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	@Override
	public String getLotteryName() {
		if (lotteryId != -1) {
			return AppLotteryInfos.getLotteryName(lotteryId);
		} else {
			return AppLotteryInfos.getLotteryName(LotteryIDUtils.ZCSFC_LOTTERY_ID_INT);
		}
	}

	@Override
	public int getLogoResID() {
		switch (lotteryId) {
			case LotteryIDUtils.ZCSFC_LOTTERY_ID_INT:
				return R.drawable.main_sfc;
			case LotteryIDUtils.ZCRXJ_LOTTERY_ID_INT:
				return R.drawable.main_ren9;
			case LotteryIDUtils.ZCBQC_LOTTERY_ID_INT:
				return R.drawable.main_zc_bqc;
			case LotteryIDUtils.ZCJQC_LOTTERY_ID_INT:
				return R.drawable.main_zc_jqc;
		}
		return R.drawable.main_zc_bqc;
	}

}
